Produced by Araxis Merge on 2023-03-13 03:01:17 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | Porto v4.0.4/Porto Theme/app/design/frontend/Smartwave/porto/web/js | jquery.parallax.min.js | 2016-10-30 15:21:36 +0000 |
| 2 | Porto v4.0.5/Porto Theme/app/design/frontend/Smartwave/porto/web/js | jquery.parallax.min.js | 2016-10-30 15:21:36 +0000 |
| Description | Between Files 1 and 2 | |
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 1 | 1122 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | Consecutive whitespace is treated as a single space |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
| Active line-pairing rules |
No regular expressions were active.
| 1 | //============================================================ | 1 | //============================================================ | |||
| 2 | // | 2 | // | |||
| 3 | // The MIT License | 3 | // The MIT License | |||
| 4 | // | 4 | // | |||
| 5 | // Copyright (C) 2014 Matthew Wagerfield - @wagerfield | 5 | // Copyright (C) 2014 Matthew Wagerfield - @wagerfield | |||
| 6 | // | 6 | // | |||
| 7 | // Permission is hereby granted, free of charge, to any | 7 | // Permission is hereby granted, free of charge, to any | |||
| 8 | // person obtaining a copy of this software and associated | 8 | // person obtaining a copy of this software and associated | |||
| 9 | // documentation files (the "Software"), to deal in the | 9 | // documentation files (the "Software"), to deal in the | |||
| 10 | // Software without restriction, including without limitation | 10 | // Software without restriction, including without limitation | |||
| 11 | // the rights to use, copy, modify, merge, publish, distribute, | 11 | // the rights to use, copy, modify, merge, publish, distribute, | |||
| 12 | // sublicense, and/or sell copies of the Software, and to | 12 | // sublicense, and/or sell copies of the Software, and to | |||
| 13 | // permit persons to whom the Software is furnished to do | 13 | // permit persons to whom the Software is furnished to do | |||
| 14 | // so, subject to the following conditions: | 14 | // so, subject to the following conditions: | |||
| 15 | // | 15 | // | |||
| 16 | // The above copyright notice and this permission notice | 16 | // The above copyright notice and this permission notice | |||
| 17 | // shall be included in all copies or substantial portions | 17 | // shall be included in all copies or substantial portions | |||
| 18 | // of the Software. | 18 | // of the Software. | |||
| 19 | // | 19 | // | |||
| 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY | 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY | |||
| 21 | // OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | 21 | // OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | |||
| 22 | // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | 22 | // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |||
| 23 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO | 23 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO | |||
| 24 | // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | 24 | // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | |||
| 25 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | 25 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | |||
| 26 | // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 26 | // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
| 27 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | 27 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | |||
| 28 | // OR OTHER DEALINGS IN THE SOFTWARE. | 28 | // OR OTHER DEALINGS IN THE SOFTWARE. | |||
| 29 | // | 29 | // | |||
| 30 | //============================================================ | 30 | //============================================================ | |||
| 31 | 31 | |||||
| 32 | /** | 32 | /** | |||
| 33 | * jQuery || Zepto Parallax Plugin | 33 | * jQuery || Zepto Parallax Plugin | |||
| 34 | * @author Matthew Wagerfield - @wagerfield | 34 | * @author Matthew Wagerfield - @wagerfield | |||
| 35 | * @description Creates a parallax effect between an array of layers, | 35 | * @description Creates a parallax effect between an array of layers, | |||
| 36 | * driving the motion from the gyroscope output of a smartdevice. | 36 | * driving the motion from the gyroscope output of a smartdevice. | |||
| 37 | * If no gyroscope is available, the cursor position is used. | 37 | * If no gyroscope is available, the cursor position is used. | |||
| 38 | */ | 38 | */ | |||
| 39 | ;(function($, window, document, undefined) { | 39 | ;(function($, window, document, undefined) { | |||
| 40 | 40 | |||||
| 41 | // Strict Mode | 41 | // Strict Mode | |||
| 42 | 'use strict'; | 42 | 'use strict'; | |||
| 43 | 43 | |||||
| 44 | // Constants | 44 | // Constants | |||
| 45 | var NAME = 'parallax'; | 45 | var NAME = 'parallax'; | |||
| 46 | var MAGIC_NUMBER = 30; | 46 | var MAGIC_NUMBER = 30; | |||
| 47 | var DEFAULTS = { | 47 | var DEFAULTS = { | |||
| 48 | relativeInput: false, | 48 | relativeInput: false, | |||
| 49 | clipRelativeInput: false, | 49 | clipRelativeInput: false, | |||
| 50 | calibrationThreshold: 100, | 50 | calibrationThreshold: 100, | |||
| 51 | calibrationDelay: 500, | 51 | calibrationDelay: 500, | |||
| 52 | supportDelay: 500, | 52 | supportDelay: 500, | |||
| 53 | calibrateX: false, | 53 | calibrateX: false, | |||
| 54 | calibrateY: true, | 54 | calibrateY: true, | |||
| 55 | invertX: true, | 55 | invertX: true, | |||
| 56 | invertY: true, | 56 | invertY: true, | |||
| 57 | limitX: false, | 57 | limitX: false, | |||
| 58 | limitY: false, | 58 | limitY: false, | |||
| 59 | scalarX: 10.0, | 59 | scalarX: 10.0, | |||
| 60 | scalarY: 10.0, | 60 | scalarY: 10.0, | |||
| 61 | frictionX: 0.1, | 61 | frictionX: 0.1, | |||
| 62 | frictionY: 0.1, | 62 | frictionY: 0.1, | |||
| 63 | originX: 0.5, | 63 | originX: 0.5, | |||
| 64 | originY: 0.5 | 64 | originY: 0.5 | |||
| 65 | }; | 65 | }; | |||
| 66 | 66 | |||||
| 67 | function Plugin(element, options) { | 67 | function Plugin(element, options) { | |||
| 68 | 68 | |||||
| 69 | // DOM Context | 69 | // DOM Context | |||
| 70 | this.element = element; | 70 | this.element = element; | |||
| 71 | 71 | |||||
| 72 | // Selections | 72 | // Selections | |||
| 73 | this.$context = $(element).data('api', this); | 73 | this.$context = $(element).data('api', this); | |||
| 74 | this.$layers = this.$context.find('.layer'); | 74 | this.$layers = this.$context.find('.layer'); | |||
| 75 | 75 | |||||
| 76 | // Data Extraction | 76 | // Data Extraction | |||
| 77 | var data = { | 77 | var data = { | |||
| 78 | calibrateX: this.$context.data('calibrate-x') || null, | 78 | calibrateX: this.$context.data('calibrate-x') || null, | |||
| 79 | calibrateY: this.$context.data('calibrate-y') || null, | 79 | calibrateY: this.$context.data('calibrate-y') || null, | |||
| 80 | invertX: this.$context.data('invert-x') || null, | 80 | invertX: this.$context.data('invert-x') || null, | |||
| 81 | invertY: this.$context.data('invert-y') || null, | 81 | invertY: this.$context.data('invert-y') || null, | |||
| 82 | limitX: parseFloat(this.$context.data('limit-x')) || null, | 82 | limitX: parseFloat(this.$context.data('limit-x')) || null, | |||
| 83 | limitY: parseFloat(this.$context.data('limit-y')) || null, | 83 | limitY: parseFloat(this.$context.data('limit-y')) || null, | |||
| 84 | scalarX: parseFloat(this.$context.data('scalar-x')) || null, | 84 | scalarX: parseFloat(this.$context.data('scalar-x')) || null, | |||
| 85 | scalarY: parseFloat(this.$context.data('scalar-y')) || null, | 85 | scalarY: parseFloat(this.$context.data('scalar-y')) || null, | |||
| 86 | frictionX: parseFloat(this.$context.data('friction-x')) || null, | 86 | frictionX: parseFloat(this.$context.data('friction-x')) || null, | |||
| 87 | frictionY: parseFloat(this.$context.data('friction-y')) || null, | 87 | frictionY: parseFloat(this.$context.data('friction-y')) || null, | |||
| 88 | originX: parseFloat(this.$context.data('origin-x')) || null, | 88 | originX: parseFloat(this.$context.data('origin-x')) || null, | |||
| 89 | originY: parseFloat(this.$context.data('origin-y')) || null | 89 | originY: parseFloat(this.$context.data('origin-y')) || null | |||
| 90 | }; | 90 | }; | |||
| 91 | 91 | |||||
| 92 | // Delete Null Data Values | 92 | // Delete Null Data Values | |||
| 93 | for (var key in data) { | 93 | for (var key in data) { | |||
| 94 | if (data[key] === null) delete data[key]; | 94 | if (data[key] === null) delete data[key]; | |||
| 95 | } | 95 | } | |||
| 96 | 96 | |||||
| 97 | // Compose Settings Object | 97 | // Compose Settings Object | |||
| 98 | $.extend(this, DEFAULTS, options, data); | 98 | $.extend(this, DEFAULTS, options, data); | |||
| 99 | 99 | |||||
| 100 | // States | 100 | // States | |||
| 101 | this.calibrationTimer = null; | 101 | this.calibrationTimer = null; | |||
| 102 | this.calibrationFlag = true; | 102 | this.calibrationFlag = true; | |||
| 103 | this.enabled = false; | 103 | this.enabled = false; | |||
| 104 | this.depths = []; | 104 | this.depths = []; | |||
| 105 | this.raf = null; | 105 | this.raf = null; | |||
| 106 | 106 | |||||
| 107 | // Element Bounds | 107 | // Element Bounds | |||
| 108 | this.bounds = null; | 108 | this.bounds = null; | |||
| 109 | this.ex = 0; | 109 | this.ex = 0; | |||
| 110 | this.ey = 0; | 110 | this.ey = 0; | |||
| 111 | this.ew = 0; | 111 | this.ew = 0; | |||
| 112 | this.eh = 0; | 112 | this.eh = 0; | |||
| 113 | 113 | |||||
| 114 | // Element Center | 114 | // Element Center | |||
| 115 | this.ecx = 0; | 115 | this.ecx = 0; | |||
| 116 | this.ecy = 0; | 116 | this.ecy = 0; | |||
| 117 | 117 | |||||
| 118 | // Element Range | 118 | // Element Range | |||
| 119 | this.erx = 0; | 119 | this.erx = 0; | |||
| 120 | this.ery = 0; | 120 | this.ery = 0; | |||
| 121 | 121 | |||||
| 122 | // Calibration | 122 | // Calibration | |||
| 123 | this.cx = 0; | 123 | this.cx = 0; | |||
| 124 | this.cy = 0; | 124 | this.cy = 0; | |||
| 125 | 125 | |||||
| 126 | // Input | 126 | // Input | |||
| 127 | this.ix = 0; | 127 | this.ix = 0; | |||
| 128 | this.iy = 0; | 128 | this.iy = 0; | |||
| 129 | 129 | |||||
| 130 | // Motion | 130 | // Motion | |||
| 131 | this.mx = 0; | 131 | this.mx = 0; | |||
| 132 | this.my = 0; | 132 | this.my = 0; | |||
| 133 | 133 | |||||
| 134 | // Velocity | 134 | // Velocity | |||
| 135 | this.vx = 0; | 135 | this.vx = 0; | |||
| 136 | this.vy = 0; | 136 | this.vy = 0; | |||
| 137 | 137 | |||||
| 138 | // Callbacks | 138 | // Callbacks | |||
| 139 | this.onMouseMove = this.onMouseMove.bind(this); | 139 | this.onMouseMove = this.onMouseMove.bind(this); | |||
| 140 | this.onDeviceOrientation = this.onDeviceOrientation.bind(this); | 140 | this.onDeviceOrientation = this.onDeviceOrientation.bind(this); | |||
| 141 | this.onOrientationTimer = this.onOrientationTimer.bind(this); | 141 | this.onOrientationTimer = this.onOrientationTimer.bind(this); | |||
| 142 | this.onCalibrationTimer = this.onCalibrationTimer.bind(this); | 142 | this.onCalibrationTimer = this.onCalibrationTimer.bind(this); | |||
| 143 | this.onAnimationFrame = this.onAnimationFrame.bind(this); | 143 | this.onAnimationFrame = this.onAnimationFrame.bind(this); | |||
| 144 | this.onWindowResize = this.onWindowResize.bind(this); | 144 | this.onWindowResize = this.onWindowResize.bind(this); | |||
| 145 | 145 | |||||
| 146 | // Initialise | 146 | // Initialise | |||
| 147 | this.initialise(); | 147 | this.initialise(); | |||
| 148 | } | 148 | } | |||
| 149 | 149 | |||||
| 150 | Plugin.prototype.transformSupport = function(value) { | 150 | Plugin.prototype.transformSupport = function(value) { | |||
| 151 | var element = document.createElement('div'); | 151 | var element = document.createElement('div'); | |||
| 152 | var propertySupport = false; | 152 | var propertySupport = false; | |||
| 153 | var propertyValue = null; | 153 | var propertyValue = null; | |||
| 154 | var featureSupport = false; | 154 | var featureSupport = false; | |||
| 155 | var cssProperty = null; | 155 | var cssProperty = null; | |||
| 156 | var jsProperty = null; | 156 | var jsProperty = null; | |||
| 157 | for (var i = 0, l = this.vendors.length; i < l; i++) { | 157 | for (var i = 0, l = this.vendors.length; i < l; i++) { | |||
| 158 | if (this.vendors[i] !== null) { | 158 | if (this.vendors[i] !== null) { | |||
| 159 | cssProperty = this.vendors[i][0] + 'transform'; | 159 | cssProperty = this.vendors[i][0] + 'transform'; | |||
| 160 | jsProperty = this.vendors[i][1] + 'Transform'; | 160 | jsProperty = this.vendors[i][1] + 'Transform'; | |||
| 161 | } else { | 161 | } else { | |||
| 162 | cssProperty = 'transform'; | 162 | cssProperty = 'transform'; | |||
| 163 | jsProperty = 'transform'; | 163 | jsProperty = 'transform'; | |||
| 164 | } | 164 | } | |||
| 165 | if (element.style[jsProperty] !== undefined) { | 165 | if (element.style[jsProperty] !== undefined) { | |||
| 166 | propertySupport = true; | 166 | propertySupport = true; | |||
| 167 | break; | 167 | break; | |||
| 168 | } | 168 | } | |||
| 169 | } | 169 | } | |||
| 170 | switch(value) { | 170 | switch(value) { | |||
| 171 | case '2D': | 171 | case '2D': | |||
| 172 | featureSupport = propertySupport; | 172 | featureSupport = propertySupport; | |||
| 173 | break; | 173 | break; | |||
| 174 | case '3D': | 174 | case '3D': | |||
| 175 | if (propertySupport) { | 175 | if (propertySupport) { | |||
| 176 | var body = document.body || document.createElement('body'); | 176 | var body = document.body || document.createElement('body'); | |||
| 177 | var documentElement = document.documentElement; | 177 | var documentElement = document.documentElement; | |||
| 178 | var documentOverflow = documentElement.style.overflow; | 178 | var documentOverflow = documentElement.style.overflow; | |||
| 179 | if (!document.body) { | 179 | if (!document.body) { | |||
| 180 | documentElement.appendChild(body); | 180 | documentElement.appendChild(body); | |||
| 181 | } | 181 | } | |||
| 182 | body.appendChild(element); | 182 | body.appendChild(element); | |||
| 183 | element.style[jsProperty] = 'translate3d(1px,1px,1px)'; | 183 | element.style[jsProperty] = 'translate3d(1px,1px,1px)'; | |||
| 184 | propertyValue = window.getComputedStyle(element).getPropertyValue(cssProperty); | 184 | propertyValue = window.getComputedStyle(element).getPropertyValue(cssProperty); | |||
| 185 | featureSupport = propertyValue !== undefined && propertyValue.length > 0 && propertyValue !== "none"; | 185 | featureSupport = propertyValue !== undefined && propertyValue.length > 0 && propertyValue !== "none"; | |||
| 186 | documentElement.style.overflow = documentOverflow; | 186 | documentElement.style.overflow = documentOverflow; | |||
| 187 | body.removeChild(element); | 187 | body.removeChild(element); | |||
| 188 | } | 188 | } | |||
| 189 | break; | 189 | break; | |||
| 190 | } | 190 | } | |||
| 191 | return featureSupport; | 191 | return featureSupport; | |||
| 192 | }; | 192 | }; | |||
| 193 | 193 | |||||
| 194 | Plugin.prototype.ww = null; | 194 | Plugin.prototype.ww = null; | |||
| 195 | Plugin.prototype.wh = null; | 195 | Plugin.prototype.wh = null; | |||
| 196 | Plugin.prototype.wcx = null; | 196 | Plugin.prototype.wcx = null; | |||
| 197 | Plugin.prototype.wcy = null; | 197 | Plugin.prototype.wcy = null; | |||
| 198 | Plugin.prototype.wrx = null; | 198 | Plugin.prototype.wrx = null; | |||
| 199 | Plugin.prototype.wry = null; | 199 | Plugin.prototype.wry = null; | |||
| 200 | Plugin.prototype.portrait = null; | 200 | Plugin.prototype.portrait = null; | |||
| 201 | Plugin.prototype.desktop = !navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|BB10|mobi|tablet|opera mini|nexus 7)/i); | 201 | Plugin.prototype.desktop = !navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|BB10|mobi|tablet|opera mini|nexus 7)/i); | |||
| 202 | Plugin.prototype.vendors = [null,['-webkit-','webkit'],['-moz-','Moz'],['-o-','O'],['-ms-','ms']]; | 202 | Plugin.prototype.vendors = [null,['-webkit-','webkit'],['-moz-','Moz'],['-o-','O'],['-ms-','ms']]; | |||
| 203 | Plugin.prototype.motionSupport = !!window.DeviceMotionEvent; | 203 | Plugin.prototype.motionSupport = !!window.DeviceMotionEvent; | |||
| 204 | Plugin.prototype.orientationSupport = !!window.DeviceOrientationEvent; | 204 | Plugin.prototype.orientationSupport = !!window.DeviceOrientationEvent; | |||
| 205 | Plugin.prototype.orientationStatus = 0; | 205 | Plugin.prototype.orientationStatus = 0; | |||
| 206 | Plugin.prototype.transform2DSupport = Plugin.prototype.transformSupport('2D'); | 206 | Plugin.prototype.transform2DSupport = Plugin.prototype.transformSupport('2D'); | |||
| 207 | Plugin.prototype.transform3DSupport = Plugin.prototype.transformSupport('3D'); | 207 | Plugin.prototype.transform3DSupport = Plugin.prototype.transformSupport('3D'); | |||
| 208 | Plugin.prototype.propertyCache = {}; | 208 | Plugin.prototype.propertyCache = {}; | |||
| 209 | 209 | |||||
| 210 | Plugin.prototype.initialise = function() { | 210 | Plugin.prototype.initialise = function() { | |||
| 211 | 211 | |||||
| 212 | // Configure Styles | 212 | // Configure Styles | |||
| 213 | if (this.$context.css('position') === 'static') { | 213 | if (this.$context.css('position') === 'static') { | |||
| 214 | this.$context.css({ | 214 | this.$context.css({ | |||
| 215 | position:'relative' | 215 | position:'relative' | |||
| 216 | }); | 216 | }); | |||
| 217 | } | 217 | } | |||
| 218 | 218 | |||||
| 219 | // Hardware Accelerate Context | 219 | // Hardware Accelerate Context | |||
| 220 | this.accelerate(this.$context); | 220 | this.accelerate(this.$context); | |||
| 221 | 221 | |||||
| 222 | // Setup | 222 | // Setup | |||
| 223 | this.updateLayers(); | 223 | this.updateLayers(); | |||
| 224 | this.updateDimensions(); | 224 | this.updateDimensions(); | |||
| 225 | this.enable(); | 225 | this.enable(); | |||
| 226 | this.queueCalibration(this.calibrationDelay); | 226 | this.queueCalibration(this.calibrationDelay); | |||
| 227 | }; | 227 | }; | |||
| 228 | 228 | |||||
| 229 | Plugin.prototype.updateLayers = function() { | 229 | Plugin.prototype.updateLayers = function() { | |||
| 230 | 230 | |||||
| 231 | // Cache Layer Elements | 231 | // Cache Layer Elements | |||
| 232 | this.$layers = this.$context.find('.layer'); | 232 | this.$layers = this.$context.find('.layer'); | |||
| 233 | this.depths = []; | 233 | this.depths = []; | |||
| 234 | 234 | |||||
| 235 | // Configure Layer Styles | 235 | // Configure Layer Styles | |||
| 236 | this.$layers.css({ | 236 | this.$layers.css({ | |||
| 237 | position:'absolute', | 237 | position:'absolute', | |||
| 238 | display:'block', | 238 | display:'block', | |||
| 239 | left: 0, | 239 | left: 0, | |||
| 240 | top: 0 | 240 | top: 0 | |||
| 241 | }); | 241 | }); | |||
| 242 | this.$layers.first().css({ | 242 | this.$layers.first().css({ | |||
| 243 | position:'relative' | 243 | position:'relative' | |||
| 244 | }); | 244 | }); | |||
| 245 | 245 | |||||
| 246 | // Hardware Accelerate Layers | 246 | // Hardware Accelerate Layers | |||
| 247 | this.accelerate(this.$layers); | 247 | this.accelerate(this.$layers); | |||
| 248 | 248 | |||||
| 249 | // Cache Depths | 249 | // Cache Depths | |||
| 250 | this.$layers.each($.proxy(function(index, element) { | 250 | this.$layers.each($.proxy(function(index, element) { | |||
| 251 | this.depths.push($(element).data('depth') || 0); | 251 | this.depths.push($(element).data('depth') || 0); | |||
| 252 | }, this)); | 252 | }, this)); | |||
| 253 | }; | 253 | }; | |||
| 254 | 254 | |||||
| 255 | Plugin.prototype.updateDimensions = function() { | 255 | Plugin.prototype.updateDimensions = function() { | |||
| 256 | this.ww = window.innerWidth; | 256 | this.ww = window.innerWidth; | |||
| 257 | this.wh = window.innerHeight; | 257 | this.wh = window.innerHeight; | |||
| 258 | this.wcx = this.ww * this.originX; | 258 | this.wcx = this.ww * this.originX; | |||
| 259 | this.wcy = this.wh * this.originY; | 259 | this.wcy = this.wh * this.originY; | |||
| 260 | this.wrx = Math.max(this.wcx, this.ww - this.wcx); | 260 | this.wrx = Math.max(this.wcx, this.ww - this.wcx); | |||
| 261 | this.wry = Math.max(this.wcy, this.wh - this.wcy); | 261 | this.wry = Math.max(this.wcy, this.wh - this.wcy); | |||
| 262 | }; | 262 | }; | |||
| 263 | 263 | |||||
| 264 | Plugin.prototype.updateBounds = function() { | 264 | Plugin.prototype.updateBounds = function() { | |||
| 265 | this.bounds = this.element.getBoundingClientRect(); | 265 | this.bounds = this.element.getBoundingClientRect(); | |||
| 266 | this.ex = this.bounds.left; | 266 | this.ex = this.bounds.left; | |||
| 267 | this.ey = this.bounds.top; | 267 | this.ey = this.bounds.top; | |||
| 268 | this.ew = this.bounds.width; | 268 | this.ew = this.bounds.width; | |||
| 269 | this.eh = this.bounds.height; | 269 | this.eh = this.bounds.height; | |||
| 270 | this.ecx = this.ew * this.originX; | 270 | this.ecx = this.ew * this.originX; | |||
| 271 | this.ecy = this.eh * this.originY; | 271 | this.ecy = this.eh * this.originY; | |||
| 272 | this.erx = Math.max(this.ecx, this.ew - this.ecx); | 272 | this.erx = Math.max(this.ecx, this.ew - this.ecx); | |||
| 273 | this.ery = Math.max(this.ecy, this.eh - this.ecy); | 273 | this.ery = Math.max(this.ecy, this.eh - this.ecy); | |||
| 274 | }; | 274 | }; | |||
| 275 | 275 | |||||
| 276 | Plugin.prototype.queueCalibration = function(delay) { | 276 | Plugin.prototype.queueCalibration = function(delay) { | |||
| 277 | clearTimeout(this.calibrationTimer); | 277 | clearTimeout(this.calibrationTimer); | |||
| 278 | this.calibrationTimer = setTimeout(this.onCalibrationTimer, delay); | 278 | this.calibrationTimer = setTimeout(this.onCalibrationTimer, delay); | |||
| 279 | }; | 279 | }; | |||
| 280 | 280 | |||||
| 281 | Plugin.prototype.enable = function() { | 281 | Plugin.prototype.enable = function() { | |||
| 282 | if (!this.enabled) { | 282 | if (!this.enabled) { | |||
| 283 | this.enabled = true; | 283 | this.enabled = true; | |||
| 284 | if (this.orientationSupport) { | 284 | if (this.orientationSupport) { | |||
| 285 | this.portrait = null; | 285 | this.portrait = null; | |||
| 286 | window.addEventListener('deviceorientation', this.onDeviceOrientation); | 286 | window.addEventListener('deviceorientation', this.onDeviceOrientation); | |||
| 287 | setTimeout(this.onOrientationTimer, this.supportDelay); | 287 | setTimeout(this.onOrientationTimer, this.supportDelay); | |||
| 288 | } else { | 288 | } else { | |||
| 289 | this.cx = 0; | 289 | this.cx = 0; | |||
| 290 | this.cy = 0; | 290 | this.cy = 0; | |||
| 291 | this.portrait = false; | 291 | this.portrait = false; | |||
| 292 | window.addEventListener('mousemove', this.onMouseMove); | 292 | window.addEventListener('mousemove', this.onMouseMove); | |||
| 293 | } | 293 | } | |||
| 294 | window.addEventListener('resize', this.onWindowResize); | 294 | window.addEventListener('resize', this.onWindowResize); | |||
| 295 | this.raf = requestAnimationFrame(this.onAnimationFrame); | 295 | this.raf = requestAnimationFrame(this.onAnimationFrame); | |||
| 296 | } | 296 | } | |||
| 297 | }; | 297 | }; | |||
| 298 | 298 | |||||
| 299 | Plugin.prototype.disable = function() { | 299 | Plugin.prototype.disable = function() { | |||
| 300 | if (this.enabled) { | 300 | if (this.enabled) { | |||
| 301 | this.enabled = false; | 301 | this.enabled = false; | |||
| 302 | if (this.orientationSupport) { | 302 | if (this.orientationSupport) { | |||
| 303 | window.removeEventListener('deviceorientation', this.onDeviceOrientation); | 303 | window.removeEventListener('deviceorientation', this.onDeviceOrientation); | |||
| 304 | } else { | 304 | } else { | |||
| 305 | window.removeEventListener('mousemove', this.onMouseMove); | 305 | window.removeEventListener('mousemove', this.onMouseMove); | |||
| 306 | } | 306 | } | |||
| 307 | window.removeEventListener('resize', this.onWindowResize); | 307 | window.removeEventListener('resize', this.onWindowResize); | |||
| 308 | cancelAnimationFrame(this.raf); | 308 | cancelAnimationFrame(this.raf); | |||
| 309 | } | 309 | } | |||
| 310 | }; | 310 | }; | |||
| 311 | 311 | |||||
| 312 | Plugin.prototype.calibrate = function(x, y) { | 312 | Plugin.prototype.calibrate = function(x, y) { | |||
| 313 | this.calibrateX = x === undefined ? this.calibrateX : x; | 313 | this.calibrateX = x === undefined ? this.calibrateX : x; | |||
| 314 | this.calibrateY = y === undefined ? this.calibrateY : y; | 314 | this.calibrateY = y === undefined ? this.calibrateY : y; | |||
| 315 | }; | 315 | }; | |||
| 316 | 316 | |||||
| 317 | Plugin.prototype.invert = function(x, y) { | 317 | Plugin.prototype.invert = function(x, y) { | |||
| 318 | this.invertX = x === undefined ? this.invertX : x; | 318 | this.invertX = x === undefined ? this.invertX : x; | |||
| 319 | this.invertY = y === undefined ? this.invertY : y; | 319 | this.invertY = y === undefined ? this.invertY : y; | |||
| 320 | }; | 320 | }; | |||
| 321 | 321 | |||||
| 322 | Plugin.prototype.friction = function(x, y) { | 322 | Plugin.prototype.friction = function(x, y) { | |||
| 323 | this.frictionX = x === undefined ? this.frictionX : x; | 323 | this.frictionX = x === undefined ? this.frictionX : x; | |||
| 324 | this.frictionY = y === undefined ? this.frictionY : y; | 324 | this.frictionY = y === undefined ? this.frictionY : y; | |||
| 325 | }; | 325 | }; | |||
| 326 | 326 | |||||
| 327 | Plugin.prototype.scalar = function(x, y) { | 327 | Plugin.prototype.scalar = function(x, y) { | |||
| 328 | this.scalarX = x === undefined ? this.scalarX : x; | 328 | this.scalarX = x === undefined ? this.scalarX : x; | |||
| 329 | this.scalarY = y === undefined ? this.scalarY : y; | 329 | this.scalarY = y === undefined ? this.scalarY : y; | |||
| 330 | }; | 330 | }; | |||
| 331 | 331 | |||||
| 332 | Plugin.prototype.limit = function(x, y) { | 332 | Plugin.prototype.limit = function(x, y) { | |||
| 333 | this.limitX = x === undefined ? this.limitX : x; | 333 | this.limitX = x === undefined ? this.limitX : x; | |||
| 334 | this.limitY = y === undefined ? this.limitY : y; | 334 | this.limitY = y === undefined ? this.limitY : y; | |||
| 335 | }; | 335 | }; | |||
| 336 | 336 | |||||
| 337 | Plugin.prototype.origin = function(x, y) { | 337 | Plugin.prototype.origin = function(x, y) { | |||
| 338 | this.originX = x === undefined ? this.originX : x; | 338 | this.originX = x === undefined ? this.originX : x; | |||
| 339 | this.originY = y === undefined ? this.originY : y; | 339 | this.originY = y === undefined ? this.originY : y; | |||
| 340 | }; | 340 | }; | |||
| 341 | 341 | |||||
| 342 | Plugin.prototype.clamp = function(value, min, max) { | 342 | Plugin.prototype.clamp = function(value, min, max) { | |||
| 343 | value = Math.max(value, min); | 343 | value = Math.max(value, min); | |||
| 344 | value = Math.min(value, max); | 344 | value = Math.min(value, max); | |||
| 345 | return value; | 345 | return value; | |||
| 346 | }; | 346 | }; | |||
| 347 | 347 | |||||
| 348 | Plugin.prototype.css = function(element, property, value) { | 348 | Plugin.prototype.css = function(element, property, value) { | |||
| 349 | var jsProperty = this.propertyCache[property]; | 349 | var jsProperty = this.propertyCache[property]; | |||
| 350 | if (!jsProperty) { | 350 | if (!jsProperty) { | |||
| 351 | for (var i = 0, l = this.vendors.length; i < l; i++) { | 351 | for (var i = 0, l = this.vendors.length; i < l; i++) { | |||
| 352 | if (this.vendors[i] !== null) { | 352 | if (this.vendors[i] !== null) { | |||
| 353 | jsProperty = $.camelCase(this.vendors[i][1] + '-' + property); | 353 | jsProperty = $.camelCase(this.vendors[i][1] + '-' + property); | |||
| 354 | } else { | 354 | } else { | |||
| 355 | jsProperty = property; | 355 | jsProperty = property; | |||
| 356 | } | 356 | } | |||
| 357 | if (element.style[jsProperty] !== undefined) { | 357 | if (element.style[jsProperty] !== undefined) { | |||
| 358 | this.propertyCache[property] = jsProperty; | 358 | this.propertyCache[property] = jsProperty; | |||
| 359 | break; | 359 | break; | |||
| 360 | } | 360 | } | |||
| 361 | } | 361 | } | |||
| 362 | } | 362 | } | |||
| 363 | element.style[jsProperty] = value; | 363 | element.style[jsProperty] = value; | |||
| 364 | }; | 364 | }; | |||
| 365 | 365 | |||||
| 366 | Plugin.prototype.accelerate = function($element) { | 366 | Plugin.prototype.accelerate = function($element) { | |||
| 367 | for (var i = 0, l = $element.length; i < l; i++) { | 367 | for (var i = 0, l = $element.length; i < l; i++) { | |||
| 368 | var element = $element[i]; | 368 | var element = $element[i]; | |||
| 369 | this.css(element, 'transform', 'translate3d(0,0,0)'); | 369 | this.css(element, 'transform', 'translate3d(0,0,0)'); | |||
| 370 | this.css(element, 'transform-style', 'preserve-3d'); | 370 | this.css(element, 'transform-style', 'preserve-3d'); | |||
| 371 | this.css(element, 'backface-visibility', 'hidden'); | 371 | this.css(element, 'backface-visibility', 'hidden'); | |||
| 372 | } | 372 | } | |||
| 373 | }; | 373 | }; | |||
| 374 | 374 | |||||
| 375 | Plugin.prototype.setPosition = function(element, x, y) { | 375 | Plugin.prototype.setPosition = function(element, x, y) { | |||
| 376 | x += 'px'; | 376 | x += 'px'; | |||
| 377 | y += 'px'; | 377 | y += 'px'; | |||
| 378 | if (this.transform3DSupport) { | 378 | if (this.transform3DSupport) { | |||
| 379 | this.css(element, 'transform', 'translate3d('+x+','+y+',0)'); | 379 | this.css(element, 'transform', 'translate3d('+x+','+y+',0)'); | |||
| 380 | } else if (this.transform2DSupport) { | 380 | } else if (this.transform2DSupport) { | |||
| 381 | this.css(element, 'transform', 'translate('+x+','+y+')'); | 381 | this.css(element, 'transform', 'translate('+x+','+y+')'); | |||
| 382 | } else { | 382 | } else { | |||
| 383 | element.style.left = x; | 383 | element.style.left = x; | |||
| 384 | element.style.top = y; | 384 | element.style.top = y; | |||
| 385 | } | 385 | } | |||
| 386 | }; | 386 | }; | |||
| 387 | 387 | |||||
| 388 | Plugin.prototype.onOrientationTimer = function(event) { | 388 | Plugin.prototype.onOrientationTimer = function(event) { | |||
| 389 | if (this.orientationSupport && this.orientationStatus === 0) { | 389 | if (this.orientationSupport && this.orientationStatus === 0) { | |||
| 390 | this.disable(); | 390 | this.disable(); | |||
| 391 | this.orientationSupport = false; | 391 | this.orientationSupport = false; | |||
| 392 | this.enable(); | 392 | this.enable(); | |||
| 393 | } | 393 | } | |||
| 394 | }; | 394 | }; | |||
| 395 | 395 | |||||
| 396 | Plugin.prototype.onCalibrationTimer = function(event) { | 396 | Plugin.prototype.onCalibrationTimer = function(event) { | |||
| 397 | this.calibrationFlag = true; | 397 | this.calibrationFlag = true; | |||
| 398 | }; | 398 | }; | |||
| 399 | 399 | |||||
| 400 | Plugin.prototype.onWindowResize = function(event) { | 400 | Plugin.prototype.onWindowResize = function(event) { | |||
| 401 | this.updateDimensions(); | 401 | this.updateDimensions(); | |||
| 402 | }; | 402 | }; | |||
| 403 | 403 | |||||
| 404 | Plugin.prototype.onAnimationFrame = function() { | 404 | Plugin.prototype.onAnimationFrame = function() { | |||
| 405 | this.updateBounds(); | 405 | this.updateBounds(); | |||
| 406 | var dx = this.ix - this.cx; | 406 | var dx = this.ix - this.cx; | |||
| 407 | var dy = this.iy - this.cy; | 407 | var dy = this.iy - this.cy; | |||
| 408 | if ((Math.abs(dx) > this.calibrationThreshold) || (Math.abs(dy) > this.calibrationThreshold)) { | 408 | if ((Math.abs(dx) > this.calibrationThreshold) || (Math.abs(dy) > this.calibrationThreshold)) { | |||
| 409 | this.queueCalibration(0); | 409 | this.queueCalibration(0); | |||
| 410 | } | 410 | } | |||
| 411 | if (this.portrait) { | 411 | if (this.portrait) { | |||
| 412 | this.mx = this.calibrateX ? dy : this.iy; | 412 | this.mx = this.calibrateX ? dy : this.iy; | |||
| 413 | this.my = this.calibrateY ? dx : this.ix; | 413 | this.my = this.calibrateY ? dx : this.ix; | |||
| 414 | } else { | 414 | } else { | |||
| 415 | this.mx = this.calibrateX ? dx : this.ix; | 415 | this.mx = this.calibrateX ? dx : this.ix; | |||
| 416 | this.my = this.calibrateY ? dy : this.iy; | 416 | this.my = this.calibrateY ? dy : this.iy; | |||
| 417 | } | 417 | } | |||
| 418 | this.mx *= this.ew * (this.scalarX / 100); | 418 | this.mx *= this.ew * (this.scalarX / 100); | |||
| 419 | this.my *= this.eh * (this.scalarY / 100); | 419 | this.my *= this.eh * (this.scalarY / 100); | |||
| 420 | if (!isNaN(parseFloat(this.limitX))) { | 420 | if (!isNaN(parseFloat(this.limitX))) { | |||
| 421 | this.mx = this.clamp(this.mx, -this.limitX, this.limitX); | 421 | this.mx = this.clamp(this.mx, -this.limitX, this.limitX); | |||
| 422 | } | 422 | } | |||
| 423 | if (!isNaN(parseFloat(this.limitY))) { | 423 | if (!isNaN(parseFloat(this.limitY))) { | |||
| 424 | this.my = this.clamp(this.my, -this.limitY, this.limitY); | 424 | this.my = this.clamp(this.my, -this.limitY, this.limitY); | |||
| 425 | } | 425 | } | |||
| 426 | this.vx += (this.mx - this.vx) * this.frictionX; | 426 | this.vx += (this.mx - this.vx) * this.frictionX; | |||
| 427 | this.vy += (this.my - this.vy) * this.frictionY; | 427 | this.vy += (this.my - this.vy) * this.frictionY; | |||
| 428 | for (var i = 0, l = this.$layers.length; i < l; i++) { | 428 | for (var i = 0, l = this.$layers.length; i < l; i++) { | |||
| 429 | var depth = this.depths[i]; | 429 | var depth = this.depths[i]; | |||
| 430 | var layer = this.$layers[i]; | 430 | var layer = this.$layers[i]; | |||
| 431 | var xOffset = this.vx * depth * (this.invertX ? -1 : 1); | 431 | var xOffset = this.vx * depth * (this.invertX ? -1 : 1); | |||
| 432 | var yOffset = this.vy * depth * (this.invertY ? -1 : 1); | 432 | var yOffset = this.vy * depth * (this.invertY ? -1 : 1); | |||
| 433 | this.setPosition(layer, xOffset, yOffset); | 433 | this.setPosition(layer, xOffset, yOffset); | |||
| 434 | } | 434 | } | |||
| 435 | this.raf = requestAnimationFrame(this.onAnimationFrame); | 435 | this.raf = requestAnimationFrame(this.onAnimationFrame); | |||
| 436 | }; | 436 | }; | |||
| 437 | 437 | |||||
| 438 | Plugin.prototype.onDeviceOrientation = function(event) { | 438 | Plugin.prototype.onDeviceOrientation = function(event) { | |||
| 439 | 439 | |||||
| 440 | // Validate environment and event properties. | 440 | // Validate environment and event properties. | |||
| 441 | if (!this.desktop && event.beta !== null && event.gamma !== null) { | 441 | if (!this.desktop && event.beta !== null && event.gamma !== null) { | |||
| 442 | 442 | |||||
| 443 | // Set orientation status. | 443 | // Set orientation status. | |||
| 444 | this.orientationStatus = 1; | 444 | this.orientationStatus = 1; | |||
| 445 | 445 | |||||
| 446 | // Extract Rotation | 446 | // Extract Rotation | |||
| 447 | var x = (event.beta || 0) / MAGIC_NUMBER; // -90 :: 90 | 447 | var x = (event.beta || 0) / MAGIC_NUMBER; // -90 :: 90 | |||
| 448 | var y = (event.gamma || 0) / MAGIC_NUMBER; // -180 :: 180 | 448 | var y = (event.gamma || 0) / MAGIC_NUMBER; // -180 :: 180 | |||
| 449 | 449 | |||||
| 450 | // Detect Orientation Change | 450 | // Detect Orientation Change | |||
| 451 | var portrait = window.innerHeight > window.innerWidth; | 451 | var portrait = window.innerHeight > window.innerWidth; | |||
| 452 | if (this.portrait !== portrait) { | 452 | if (this.portrait !== portrait) { | |||
| 453 | this.portrait = portrait; | 453 | this.portrait = portrait; | |||
| 454 | this.calibrationFlag = true; | 454 | this.calibrationFlag = true; | |||
| 455 | } | 455 | } | |||
| 456 | 456 | |||||
| 457 | // Set Calibration | 457 | // Set Calibration | |||
| 458 | if (this.calibrationFlag) { | 458 | if (this.calibrationFlag) { | |||
| 459 | this.calibrationFlag = false; | 459 | this.calibrationFlag = false; | |||
| 460 | this.cx = x; | 460 | this.cx = x; | |||
| 461 | this.cy = y; | 461 | this.cy = y; | |||
| 462 | } | 462 | } | |||
| 463 | 463 | |||||
| 464 | // Set Input | 464 | // Set Input | |||
| 465 | this.ix = x; | 465 | this.ix = x; | |||
| 466 | this.iy = y; | 466 | this.iy = y; | |||
| 467 | } | 467 | } | |||
| 468 | }; | 468 | }; | |||
| 469 | 469 | |||||
| 470 | Plugin.prototype.onMouseMove = function(event) { | 470 | Plugin.prototype.onMouseMove = function(event) { | |||
| 471 | 471 | |||||
| 472 | // Cache mouse coordinates. | 472 | // Cache mouse coordinates. | |||
| 473 | var clientX = event.clientX; | 473 | var clientX = event.clientX; | |||
| 474 | var clientY = event.clientY; | 474 | var clientY = event.clientY; | |||
| 475 | 475 | |||||
| 476 | // Calculate Mouse Input | 476 | // Calculate Mouse Input | |||
| 477 | if (!this.orientationSupport && this.relativeInput) { | 477 | if (!this.orientationSupport && this.relativeInput) { | |||
| 478 | 478 | |||||
| 479 | // Clip mouse coordinates inside element bounds. | 479 | // Clip mouse coordinates inside element bounds. | |||
| 480 | if (this.clipRelativeInput) { | 480 | if (this.clipRelativeInput) { | |||
| 481 | clientX = Math.max(clientX, this.ex); | 481 | clientX = Math.max(clientX, this.ex); | |||
| 482 | clientX = Math.min(clientX, this.ex + this.ew); | 482 | clientX = Math.min(clientX, this.ex + this.ew); | |||
| 483 | clientY = Math.max(clientY, this.ey); | 483 | clientY = Math.max(clientY, this.ey); | |||
| 484 | clientY = Math.min(clientY, this.ey + this.eh); | 484 | clientY = Math.min(clientY, this.ey + this.eh); | |||
| 485 | } | 485 | } | |||
| 486 | 486 | |||||
| 487 | // Calculate input relative to the element. | 487 | // Calculate input relative to the element. | |||
| 488 | this.ix = (clientX - this.ex - this.ecx) / this.erx; | 488 | this.ix = (clientX - this.ex - this.ecx) / this.erx; | |||
| 489 | this.iy = (clientY - this.ey - this.ecy) / this.ery; | 489 | this.iy = (clientY - this.ey - this.ecy) / this.ery; | |||
| 490 | 490 | |||||
| 491 | } else { | 491 | } else { | |||
| 492 | 492 | |||||
| 493 | // Calculate input relative to the window. | 493 | // Calculate input relative to the window. | |||
| 494 | this.ix = (clientX - this.wcx) / this.wrx; | 494 | this.ix = (clientX - this.wcx) / this.wrx; | |||
| 495 | this.iy = (clientY - this.wcy) / this.wry; | 495 | this.iy = (clientY - this.wcy) / this.wry; | |||
| 496 | } | 496 | } | |||
| 497 | }; | 497 | }; | |||
| 498 | 498 | |||||
| 499 | var API = { | 499 | var API = { | |||
| 500 | enable: Plugin.prototype.enable, | 500 | enable: Plugin.prototype.enable, | |||
| 501 | disable: Plugin.prototype.disable, | 501 | disable: Plugin.prototype.disable, | |||
| 502 | updateLayers: Plugin.prototype.updateLayers, | 502 | updateLayers: Plugin.prototype.updateLayers, | |||
| 503 | calibrate: Plugin.prototype.calibrate, | 503 | calibrate: Plugin.prototype.calibrate, | |||
| 504 | friction: Plugin.prototype.friction, | 504 | friction: Plugin.prototype.friction, | |||
| 505 | invert: Plugin.prototype.invert, | 505 | invert: Plugin.prototype.invert, | |||
| 506 | scalar: Plugin.prototype.scalar, | 506 | scalar: Plugin.prototype.scalar, | |||
| 507 | limit: Plugin.prototype.limit, | 507 | limit: Plugin.prototype.limit, | |||
| 508 | origin: Plugin.prototype.origin | 508 | origin: Plugin.prototype.origin | |||
| 509 | }; | 509 | }; | |||
| 510 | 510 | |||||
| 511 | $.fn[NAME] = function (value) { | 511 | $.fn[NAME] = function (value) { | |||
| 512 | var args = arguments; | 512 | var args = arguments; | |||
| 513 | return this.each(function () { | 513 | return this.each(function () { | |||
| 514 | var $this = $(this); | 514 | var $this = $(this); | |||
| 515 | var plugin = $this.data(NAME); | 515 | var plugin = $this.data(NAME); | |||
| 516 | if (!plugin) { | 516 | if (!plugin) { | |||
| 517 | plugin = new Plugin(this, value); | 517 | plugin = new Plugin(this, value); | |||
| 518 | $this.data(NAME, plugin); | 518 | $this.data(NAME, plugin); | |||
| 519 | } | 519 | } | |||
| 520 | if (API[value]) { | 520 | if (API[value]) { | |||
| 521 | plugin[value].apply(plugin, Array.prototype.slice.call(args, 1)); | 521 | plugin[value].apply(plugin, Array.prototype.slice.call(args, 1)); | |||
| 522 | } | 522 | } | |||
| 523 | }); | 523 | }); | |||
| 524 | }; | 524 | }; | |||
| 525 | 525 | |||||
| 526 | })(window.jQuery || window.Zepto, window, document); | 526 | })(window.jQuery || window.Zepto, window, document); | |||
| 527 | 527 | |||||
| 528 | /** | 528 | /** | |||
| 529 | * Request Animation Frame Polyfill. | 529 | * Request Animation Frame Polyfill. | |||
| 530 | * @author Tino Zijdel | 530 | * @author Tino Zijdel | |||
| 531 | * @author Paul Irish | 531 | * @author Paul Irish | |||
| 532 | * @see https://gist.github.com/paulirish/1579671 | 532 | * @see https://gist.github.com/paulirish/1579671 | |||
| 533 | */ | 533 | */ | |||
| 534 | ;(function() { | 534 | ;(function() { | |||
| 535 | 535 | |||||
| 536 | var lastTime = 0; | 536 | var lastTime = 0; | |||
| 537 | var vendors = ['ms', 'moz', 'webkit', 'o']; | 537 | var vendors = ['ms', 'moz', 'webkit', 'o']; | |||
| 538 | 538 | |||||
| 539 | for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { | 539 | for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { | |||
| 540 | window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; | 540 | window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; | |||
| 541 | window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; | 541 | window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; | |||
| 542 | } | 542 | } | |||
| 543 | 543 | |||||
| 544 | if (!window.requestAnimationFrame) { | 544 | if (!window.requestAnimationFrame) { | |||
| 545 | window.requestAnimationFrame = function(callback, element) { | 545 | window.requestAnimationFrame = function(callback, element) { | |||
| 546 | var currTime = new Date().getTime(); | 546 | var currTime = new Date().getTime(); | |||
| 547 | var timeToCall = Math.max(0, 16 - (currTime - lastTime)); | 547 | var timeToCall = Math.max(0, 16 - (currTime - lastTime)); | |||
| 548 | var id = window.setTimeout(function() { callback(currTime + timeToCall); }, | 548 | var id = window.setTimeout(function() { callback(currTime + timeToCall); }, | |||
| 549 | timeToCall); | 549 | timeToCall); | |||
| 550 | lastTime = currTime + timeToCall; | 550 | lastTime = currTime + timeToCall; | |||
| 551 | return id; | 551 | return id; | |||
| 552 | }; | 552 | }; | |||
| 553 | } | 553 | } | |||
| 554 | 554 | |||||
| 555 | if (!window.cancelAnimationFrame) { | 555 | if (!window.cancelAnimationFrame) { | |||
| 556 | window.cancelAnimationFrame = function(id) { | 556 | window.cancelAnimationFrame = function(id) { | |||
| 557 | clearTimeout(id); | 557 | clearTimeout(id); | |||
| 558 | }; | 558 | }; | |||
| 559 | } | 559 | } | |||
| 560 | 560 | |||||
| 561 | }()); | 561 | }()); |
Araxis Merge (but not the data content of this report) is Copyright © 1993–2019 Araxis Ltd (www.araxis.com). All rights reserved.